package com.leen.admin.controller;

import com.leen.admin.dto.DeptDto;
import com.leen.admin.entity.Dept;
import com.leen.admin.entity.Role;
import com.leen.admin.repository.DeptRepository;
import com.leen.admin.service.DeptService;
import com.leen.common.vo.ResponseVO;
import com.leen.common.vo.ResultEnum;
import com.leen.common.vo.ResultVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 部门接口
 * @author xjl
 * @date 2021-05-19
 */
@RestController
@Api(tags = "部门接口API")
@RequestMapping(value = "/admin")
public class DeptController {
    @Autowired
    private DeptService deptService;

    @ApiOperation(value = "查询数据")
    @GetMapping(value = "/dept/data")
    public ResultVO<Dept> search(DeptDto deptDto){
        return ResultVO.success(this.deptService.search(deptDto));
    }

    @ApiOperation(value = "新增数据")
    @PostMapping(value = "/dept/add")
    public ResultVO<String> add(@RequestBody Dept dept){
        Dept save =this.deptService.save(dept);
        return save!=null? ResultVO.success(ResultEnum.DB_SUCCESS):ResultVO.failed(ResultEnum.DB_FAILED);
    }


    @ApiOperation(value = "修改数据")
    @PostMapping(value = "/dept/updata")
    public ResultVO<String> updata(Dept dept){
        Dept updata = this.deptService.save(dept);
        return updata!=null? ResultVO.success(ResultEnum.DB_SUCCESS):ResultVO.failed(ResultEnum.DB_FAILED);
    }


    @ApiOperation(value = "分页查询")
    @PostMapping(value = "/dept/searchPage")
    public ResultVO<String> searchPage(DeptDto deptDto){
        ResponseVO search = this.deptService.search(deptDto);
        return  ResultVO.success(search);
    }



}
